﻿
using MySchool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyKTV.ssr
{
    public partial class Form3 : Form
    {
        DBHelper dB = new DBHelper();
        DataSet ds = new DataSet();
        SqlDataAdapter adapter;
        string address = "";
        int a;

        public Form3()
        {
            InitializeComponent();
        }
        
        private void 歌手查询_Load(object sender, EventArgs e)
        {
            //赋值
            dB.OpenConnection();
            string sql = "select singer_name,singertype_name,singer_gender,singer_photo_url,singer_description from singer_info" +
                    " inner join singer_type on singer_info.singertype_id = singer_type.singertype_id ";
            adapter = new SqlDataAdapter(sql, dB.Connection);
            adapter.Fill(ds, "singer_info");
            this.dgvshow.DataSource = ds.Tables["singer_info"];
            dB.CloseConnection();
            FillCbo();
        }

        private void Filldgv()
        {
            
        }
        private void FillCbo()
        {
            
        }

        private void btncha_Click(object sender, EventArgs e)
        {
            dB.OpenConnection();
            ds.Tables["singer_info"].Clear();
            if (btncha.Text.ToString() == "大陆")
            {
                address = "1";
            }
            else if (btncha.Text.ToString() == "香港")
            {
                address = "2";

            }
            else if (btncha.Text.ToString() == "台湾")
            {
                address = "3";

            }
            else if (btncha.Text.ToString() == "欧美")
            {
                address = "4";

            }
            else if (btncha.Text.ToString() == "日韩")
            {
                address = "5";

            }
            dB.OpenConnection();
            string sql = "";
            int p;
            if (this.cboleixing.Text == "全部")
            {
                if (txtgeming.Text != null)
                {
     
                    p = adapter.Fill(ds, "singer_info");
                    if (p == 0)
                    {
                        MessageBox.Show("没有查询到");
                    }
                    this.dgvshow.DataSource = ds.Tables["singer_info"];
                }
                else
                {
                    sql = "select singer_name,singertype_name,singer_gender,singer_photo_url,singer_description from singer_info  inner join singer_type on singer_info.singertype_id=singer_type.singertype_id";
                    SqlDataAdapter adapter = new SqlDataAdapter(sql, dB.Connection);
                    adapter.Fill(ds, "singer_info");
                    this.dgvshow.DataSource = ds.Tables["singer_info"];
                }
            }
            else if (this.cboleixing.Text != "全部")
            {
                if (!txtgeming.Text.Equals(string.Empty))
                {
                    sql = " select singer_name,singertype_name,singer_gender,singer_photo_url,singer_description from singer_info  inner join singer_type on singer_info.singertype_id=singer_type.singertype_id where singer_name like N'%"+this.txtgeming.Text+"%'";
                    SqlDataAdapter adapter1 = new SqlDataAdapter(sql, dB.Connection);
                    p = adapter1.Fill(ds, "singer_info");
                    this.dgvshow.DataSource = ds.Tables["singer_info"];
                    if (p == 0)
                    {
                        MessageBox.Show("没有查询到");
                    }
                }
                else
                {
                    sql = "select singer_name,singertype_name,singer_gender,singer_photo_url,singer_description from singer_info  inner join singer_type on singer_info.singertype_id=singer_type.singertype_id where singertype_name like N'" + this.cboleixing.Text + "'";
                    SqlDataAdapter adapter = new SqlDataAdapter(sql, dB.Connection);
                    adapter.Fill(ds, "singer_info");
                    this.dgvshow.DataSource = ds.Tables["singer_info"];
                }
            }
        }
        private void cboleixing_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dev = MessageBox.Show("是否删除", "错误提示框", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (dev == DialogResult.Yes)
            {
                dB.OpenConnection();
                string singer_name = this.dgvshow.SelectedRows[0].Cells["singer_name"].Value.ToString();
                string str = "delete  singer_info where singer_name=N'" + singer_name + "'";
                SqlCommand command = new SqlCommand(str, dB.Connection);
                int sc = command.ExecuteNonQuery();
                if (sc > 0)
                {
                    MessageBox.Show("删除成功");
                    ds.Tables["singer_info"].Clear();
                    str = " select singer_name,singertype_name,singer_gender,singer_photo_url,singer_description from singer_info  inner join singer_type on singer_info.singertype_id=singer_type.singertype_id where singer_name like N'%" + this.txtgeming.Text + "%'";
                    SqlDataAdapter adapter1 = new SqlDataAdapter(str, dB.Connection);
                    adapter.Fill(ds, "singer_info");
                    this.dgvshow.DataSource = ds.Tables["singer_info"];
                    Filldgv();
                }
                else
                {
                    MessageBox.Show("删除失败1");
                }
            }
        }
           
 
            

        private void txtgeming_TextChanged(object sender, EventArgs e)
        {

        }

        private void 更改ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            dB.OpenConnection();
            
            string str = "delete  singer_info where singer_name=N'" + singer_name + "'";
            
            Form8 fm = new Form8();
            //fm.singer_id = this.dgvshow.SelectedRows[0].Cells["singer_id"].Value.ToString();
            fm.singertype_name = this.dgvshow.SelectedRows[0].Cells["singertype_name"].Value.ToString();
            fm.singer_name = this.dgvshow.SelectedRows[0].Cells["singer_name"].Value.ToString();
            fm.singer_gender = this.dgvshow.SelectedRows[0].Cells["singer_gender"].Value.ToString();
            fm.singer_photo_url = this.dgvshow.SelectedRows[0].Cells["singer_photo_url"].Value.ToString();
            fm.singer_description = this.dgvshow.SelectedRows[0].Cells["singer_description"].Value.ToString();
            ds.Tables["singer_info"].Clear();
            //         fm.Lu = this.dgvshow.SelectedRows[0].Cells["singer_photo_url"].Value.ToString();
            fm.Show();

            str = "select singer_name,singer_type.singertype_name,singer_gender,singer_photo_url,singer_description from singer_info inner join singer_type on singer_type.singertype_id  =singer_info.singertype_id  order by singer_id desc";
            adapter = new SqlDataAdapter(str, dB.Connection);
            adapter.Fill(ds, "singer_info");
            this.dgvshow.DataSource = ds.Tables["singer_info"];




        }
    }
    }


